package com.chare.Controller;



import com.chare.pojo.Position;
import com.chare.pojo.RespBean;
import com.chare.service.IPositionService;
import io.swagger.annotations.ApiModelProperty;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;



import java.util.Arrays;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author shi
 * @since 2022-06-17
 */
@RestController
@RequestMapping("/system/cfg/pos")
public class PositionController {
@Autowired
    private IPositionService service;
@ApiModelProperty("获取所有职位信息")
@GetMapping("/")
    public List<Position> getAll()
{
   return service.list();
}
@ApiModelProperty("添加新的职位")
    @PostMapping("/")
    public RespBean add(@RequestBody Position position)
{
  boolean tr= service.save(position);
  if(tr)
  {
      return RespBean.success("添加成功");
  }
  else {
      return RespBean.error("添加失败");
  }

}
@ApiModelProperty("删除")
    @DeleteMapping("/{id}")
    public RespBean delete(@PathVariable Integer id)
{
   if( service.removeById(id))
   {
    return    RespBean.success("删除成功");
   }
   else
   {
     return   RespBean.error("删除失败");
   }

}

    @ApiModelProperty("更新")
    @PutMapping("/")
    public RespBean update(@RequestBody Position position){

    if(service.updateById(position))
    {
       return RespBean.success("更新成功");
    }
      return RespBean.error("更新失败");

    }
    @ApiModelProperty("批量删除")
    @DeleteMapping("/")
    public  RespBean deleteBach(Integer ids[])
    {
       if( service.removeByIds(Arrays.asList(ids)))
       {
           return  RespBean.success("删除成功"+Arrays.toString(ids));
       }
      return RespBean.success("删除失败");
    }
}
